package demo02;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;

public class test2 {
	 public static void main(String[] args) {
	        ArrayList<String> maleStudentList = new ArrayList<>();
	        ArrayList<String> femaleStudentList = new ArrayList<>();

	        try (BufferedReader br = new BufferedReader(new FileReader("names.txt"))) {
	            String line;
	            while ((line = br.readLine()) != null) {
	            	String[] parts = line.split("-");
	            	if (parts[1].equals("男")) {
	                    maleStudentList.add(line);
	                } else if (parts[1].equals("女")) {
	                    femaleStudentList.add(line);
	                }
	            }
	        } catch (IOException e) {
	            e.getMessage();
	        }
	        Random random = new Random();
	        String randomStudent;
	        if (random.nextDouble() < 0.7) {
	            randomStudent = maleStudentList.get(random.nextInt(maleStudentList.size()));
	        } else {
	            randomStudent = femaleStudentList.get(random.nextInt(femaleStudentList.size()));
	        }

	        System.out.println("随机学生为: " + randomStudent);
	    }
	
}
